//
//  NKTabBarController.m
//  NekaPrice
//
//  Created by yu on 2018/6/18.
//  Copyright © 2018年 ma c. All rights reserved.
//

#import "NKTabBarController.h"
#import "HomeViewController.h"
#import "ExampleViewController.h"
#import "ConnectViewController.h"
#import "CustomeNavigationController.h"
#import "UITabBar+Compact.h"
@interface NKTabBarController ()<UITabBarControllerDelegate>

@end

@implementation NKTabBarController

- (instancetype)init {
    if (self = [super init]) {
        self.view.backgroundColor = [UIColor whiteColor];
        [self setupChildViewControllers];
        self.delegate = self;
    }
    return self;
}

- (void)setupChildViewControllers {
    NSArray *array = @[@{@"className": @"HomeViewController",
                         @"title": @"报价",
                         @"img": @"tabbar_price",
                         @"selectedImg": @"tabbar_price_active"
                         },
                       @{@"className": @"StoreViewController",
                         @"title": @"门店",
                         @"img": @"tabbar_store",
                         @"selectedImg": @"tabbar_store_active"
                         },
                       @{@"className": @"ExampleViewController",
                         @"title": @"案例",
                         @"img": @"tabbar_case",
                         @"selectedImg": @"tabbar_case_active"
                         },
                       @{@"className": @"WarrantyViewController",
                         @"title": @"质保",
                         @"img": @"tabbar_warranty",
                         @"selectedImg": @"tabbar_warranty_active"
                         }
//                       @{@"className": @"ConnectViewController",
//                         @"title": @"联系耐卡",
//                         @"img": @"footer_my",
//                         @"selectedImg": @"footer_my_active"
//                         }
                       ];
   
    for (NSDictionary *dic in array) {
        [self setupChildViewControllerWithClassName:dic[@"className"] title:dic[@"title"] imgName:dic[@"img"] selectedImgName:dic[@"selectedImg"]];
    }
    
}

- (void)setupChildViewControllerWithClassName:(NSString *)className title:(NSString *)title imgName:(NSString *)imgName selectedImgName:(NSString *)selectedImgName {
    Class class = NSClassFromString(className);
    UIViewController *vc = [[class alloc] init];
    vc.title = title;
    vc.tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:[UIImage imageNamed:imgName] selectedImage:[UIImage imageNamed:selectedImgName]];
    CustomeNavigationController *nav = [[CustomeNavigationController alloc] initWithRootViewController:vc];
    [self addChildViewController:nav];
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
    NSLog(@"%@", item);
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    NSLog(@"%lu", self.selectedIndex);
    [[NSNotificationCenter defaultCenter] postNotificationName:@"SELECT_CONNECT_VIEWCONTROLLER" object:nil];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
}






@end
